//
//  MTBaseTableViewController.swift
//  MTWeiBo
//
//  Created by user on 2017/7/23.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

class MTBaseTableViewController: UITableViewController,MTVisitorViewDelegate {
    //是否登录标记
    var isLogin: Bool = MTUserAccountViewModel.shardViewModel.islogin
    //访客视图
    var visitor: MTVisitorView?
    // 自定义视图loadView里面写, 重写loadView目的就是要自定义控制器的视图
    override func loadView() {
        if isLogin {
            
            super.loadView()
        }else{
            
            visitor = MTVisitorView()
            //  设置点击登录或者注册执行的闭包
            visitor?.loginCallBack = { [unowned self] in
                print(self)
                print("登录闭包")
                self.entherLogin()
            }
            //遵守协议
            visitor?.delegate = self
            //设置导航栏
            setupNavUI()
            view = visitor
            
            
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    func setupNavUI() {
        
        //设置导航栏左右安妮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册",target: self ,action: #selector(registerAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录",target: self ,action: #selector(loginAction))
    }
    
    @objc private func registerAction() {
        entherLogin()
        print("注册")
    }
    
    @objc private func loginAction() {
        entherLogin()
        print("登录")
    }
    
    //代理方法
    func loginOperation() {
        print("登录代理")
    }
    
    //微博登录界面
    private func entherLogin() {
        
        let oauthVC = MTOAuthViewController()
        let nav = MTNavViewController(rootViewController: oauthVC)
        self.present(nav, animated: true, completion: nil)
        
        
    }
    
}
